package com.lenovo.smarttraffic;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.lenovo.smarttraffic.ui.adapter.SplashAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Amoly
 * @date 2019/4/11.
 * description：
 */
public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_splash);

        if (getSharedPreferences(Constant.PREF, Context.MODE_PRIVATE).getBoolean(Constant.PREF_FIRST_RUN, true)) {
            ViewPager viewPager = findViewById(R.id.splash_vp);

            List<Integer> imgIds = new ArrayList<>();
            imgIds.add(R.drawable.bg_splash);
            imgIds.add(R.mipmap.bg);
            imgIds.add(R.mipmap.bg);

            viewPager.setAdapter(new SplashAdapter(this, imgIds));
            viewPager.setOffscreenPageLimit(imgIds.size());
        } else {
            findViewById(R.id.splash_img_def).setVisibility(View.VISIBLE);

            //延时跳转主页面
            InitApp.getHandler().postDelayed(() -> {
                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }, 1000);
        }
    }

}
